package org.op.service.doc;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class ClipboardServiceImpl implements ClipboardService {

	public void addTextToClipboard(String text) {
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	    
		StringSelection data = new StringSelection (text);
	    clipboard.setContents (data, data);
	}

	public String getTextFromClipboard() {
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	    Transferable clipData = clipboard.getContents(clipboard);
	    String s = "";
	    try {
			s = (String)(clipData.getTransferData(DataFlavor.stringFlavor));
		} catch (UnsupportedFlavorException e) {
		} catch (IOException e) {
		}
	    return s;
	}
}
